package com.preskool.service.impl;

import com.github.pagehelper.PageHelper;
import com.preskool.dto.ActionResult;
import com.preskool.mapper.HostelMapper;
import com.preskool.po.Hostel;
import com.preskool.service.HostelService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HostelServiceimpl implements HostelService {

    @Autowired(required = false)
    private HostelMapper hostelMapper;

    //分页全查
    @Override
    public List<Hostel> findAllHostel(Integer currentPage, Integer pageSize) {
//        PageHelper.startPage(currentPage, pageSize);
        List<Hostel> allHost = hostelMapper.findAllHostel((currentPage-1)*pageSize,pageSize);
        return allHost;
    }

    @Override
    public Integer delHostel(Integer roomNo) {
        return hostelMapper.delHostel(roomNo);


    }

    @Override
    public Boolean update(Hostel hostel) {
        int i = hostelMapper.update(hostel);
        if (i > -1) {
            return true;
        }
        return false;

    }

    @Override
    public Hostel findOneByroomNo(Integer roomNo) {
        return hostelMapper.findOneByroomNo(roomNo);


    }

    @Override
    public Integer add(Hostel hostel) {
        return hostelMapper.add(hostel);


    }

    @Override
    public List<Hostel> findByType(String roomType) {
        List<Hostel> byType = hostelMapper.findByType("%"+roomType+"%");

        return byType;
    }
}
